#!/bin/sh
#JAVA_HOME=
if [ -z "$JAVA_HOME" ] ; then
        echo "Error: JAVA_HOME is not defined correctly."
        exit 1
fi

cd `dirname $0`/
BASE=`pwd`

JAVA=$JAVA_HOME/bin/java
JAR_FILES="$BASE/lib/*.jar"
APPLICATION=org.webmq.main.BootstrapServer
APPLICATION_NAME=" -Dapplication.name=webmq-server"
STATIC_FILE_PATH=./static/

if `ps -ef |grep "$APPLICATION_NAME"|grep -v grep > /dev/null`  
then
	echo "`date` webmq server is Running....." 
    	exit 1
fi
    
CLASSPATH="$CLASSPATH"    
for JAR_FILE in $JAR_FILES
do
  CLASSPATH=$CLASSPATH:$JAR_FILE
done


TIMESTAMP=`date +%Y_%m_%d_%H_%M_%S`
LOGSAVED=$BASE/logs/logs_saved
STDOUT=$BASE/logs/nohup.log

if [ ! -d $LOGSAVED ]; then
   mkdir -p $LOGSAVED
fi

if [ -f $STDOUT ]; then
   mv -f $STDOUT $LOGSAVED/old_log.$TIMESTAMP
fi

JAVA_OPTS=" "

nohup $JAVA $JAVA_OPTS $APPLICATION_NAME  -classpath "$CLASSPATH" $APPLICATION $STATIC_FILE_PATH > $STDOUT & 


